5
5
6
6
import * as dom from '../../../../../../base/browser/dom.js' ;
7
7
import { decodeBase64 } from '../../../../../../base/common/buffer.js' ;
8
- import { CancellationToken } from '../../../../../../base/common/cancellation.js' ;
8
+ import { CancellationTokenSource } from '../../../../../../base/common/cancellation.js' ;
9
9
import { Codicon } from '../../../../../../base/common/codicons.js' ;
10
10
import { ThemeIcon } from '../../../../../../base/common/themables.js' ;
11
11
import { localize } from '../../../../../../nls.js' ;
@@ -18,11 +18,14 @@ import { IChatContentPartRenderContext } from '../chatContentParts.js';
18
18
import { ChatCustomProgressPart } from '../chatProgressContentPart.js' ;
19
19
import { BaseChatToolInvocationSubPart } from './chatToolInvocationSubPart.js' ;
20
20
21
+ // TODO: see if we can reuse existing types instead of adding ChatToolOutputSubPart
21
22
export class ChatToolOutputSubPart extends BaseChatToolInvocationSubPart {
22
23
public readonly domNode : HTMLElement ;
23
24
24
25
public override readonly codeblocks : IChatCodeBlockInfo [ ] = [ ] ;
25
26
27
+ private readonly _disposeCts = this . _register ( new CancellationTokenSource ( ) ) ;
28
+
26
29
constructor (
27
30
toolInvocation : IChatToolInvocation | IChatToolInvocationSerialized ,
28
31
_context : IChatContentPartRenderContext ,
@@ -44,6 +47,11 @@ export class ChatToolOutputSubPart extends BaseChatToolInvocationSubPart {
44
47
this . domNode = this . createOutputPart ( details ) ;
45
48
}
46
49
50
+ public override dispose ( ) : void {
51
+ this . _disposeCts . dispose ( true ) ;
52
+ super . dispose ( ) ;
53
+ }
54
+
47
55
private createOutputPart ( details : IToolResultOutputDetails ) : HTMLElement {
48
56
const parent = dom . $ ( 'div.webview-output' ) ;
49
57
parent . style . maxHeight = '80vh' ;
@@ -53,7 +61,12 @@ export class ChatToolOutputSubPart extends BaseChatToolInvocationSubPart {
53
61
const progressPart = this . instantiationService . createInstance ( ChatCustomProgressPart , progressMessage , ThemeIcon . modify ( Codicon . loading , 'spin' ) ) ;
54
62
parent . appendChild ( progressPart . domNode ) ;
55
63
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
+
57
70
this . _register ( renderedItem ) ;
58
71
59
72
progressPart . domNode . remove ( ) ;
@@ -62,6 +75,9 @@ export class ChatToolOutputSubPart extends BaseChatToolInvocationSubPart {
62
75
this . _register ( renderedItem . onDidChangeHeight ( ( ) => {
63
76
this . _onDidChangeHeight . fire ( ) ;
64
77
} ) ) ;
78
+ } , ( error ) => {
79
+ // TODO: show error in UI too
80
+ console . error ( 'Error rendering tool output:' , error ) ;
65
81
} ) ;
66
82
67
83
return parent ;
0 commit comments