Skip to content

Commit 6889988

Browse files
committed
More fixes
1 parent 07e43ac commit 6889988

File tree

5 files changed

+35
-10
lines changed

5 files changed

+35
-10
lines changed

extensions/markdown-language-features/src/extension.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ function registerTestOutputRenderer() {
7575
async renderChatOutput(data, webview, _token) {
7676
const decodedData = new TextDecoder().decode(data);
7777

78+
webview.options = {
79+
enableScripts: true,
80+
};
81+
7882
webview.html = `<!DOCTYPE html>
7983
<html lang="en">
8084
<head>
@@ -84,6 +88,15 @@ function registerTestOutputRenderer() {
8488
</head>
8589
<body>
8690
${decodedData}
91+
92+
<script>
93+
setInterval(() => {
94+
const el = document.createElement('div');
95+
el.textContent = 'This is a test output rendered by the test renderer.';
96+
el.style.color = 'blue';
97+
document.body.appendChild(el);
98+
}, 2000);
99+
</script>
87100
</body>
88101
</html>`;
89102

src/vs/workbench/contrib/chat/browser/chatContentParts/toolInvocationParts/chatToolOutputPart.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,16 @@
66
import * as dom from '../../../../../../base/browser/dom.js';
77
import { decodeBase64 } from '../../../../../../base/common/buffer.js';
88
import { CancellationToken } from '../../../../../../base/common/cancellation.js';
9+
import { Codicon } from '../../../../../../base/common/codicons.js';
10+
import { ThemeIcon } from '../../../../../../base/common/themables.js';
11+
import { localize } from '../../../../../../nls.js';
12+
import { IInstantiationService } from '../../../../../../platform/instantiation/common/instantiation.js';
913
import { IChatToolInvocation, IChatToolInvocationSerialized, IToolResultOutputDetailsSerialized } from '../../../common/chatService.js';
1014
import { IToolResultOutputDetails } from '../../../common/languageModelToolsService.js';
1115
import { IChatCodeBlockInfo } from '../../chat.js';
1216
import { IChatOutputRendererService } from '../../chatOutputItemRenderer.js';
1317
import { IChatContentPartRenderContext } from '../chatContentParts.js';
18+
import { ChatCustomProgressPart } from '../chatProgressContentPart.js';
1419
import { BaseChatToolInvocationSubPart } from './chatToolInvocationSubPart.js';
1520

1621
export class ChatToolOutputSubPart extends BaseChatToolInvocationSubPart {
@@ -22,32 +27,37 @@ export class ChatToolOutputSubPart extends BaseChatToolInvocationSubPart {
2227
toolInvocation: IChatToolInvocation | IChatToolInvocationSerialized,
2328
_context: IChatContentPartRenderContext,
2429
@IChatOutputRendererService private readonly chatOutputItemRendererService: IChatOutputRendererService,
30+
@IInstantiationService private readonly instantiationService: IInstantiationService,
2531
) {
2632
super(toolInvocation);
2733

28-
2934
const details: IToolResultOutputDetails = toolInvocation.kind === 'toolInvocation'
3035
? toolInvocation.resultDetails as IToolResultOutputDetails
3136
: {
3237
output: {
3338
type: 'data',
34-
mimeType: (toolInvocation.resultDetails as IToolResultOutputDetailsSerialized).mimeType,
35-
value: decodeBase64((toolInvocation.resultDetails as IToolResultOutputDetailsSerialized).base64Data),
39+
mimeType: (toolInvocation.resultDetails as IToolResultOutputDetailsSerialized).output.mimeType,
40+
value: decodeBase64((toolInvocation.resultDetails as IToolResultOutputDetailsSerialized).output.base64Data),
3641
},
3742
};
3843

3944
this.domNode = this.createOutputPart(details);
4045
}
4146

4247
private createOutputPart(details: IToolResultOutputDetails): HTMLElement {
43-
// TODO: Show progress while rendering
44-
4548
const parent = dom.$('div.webview-output');
4649
parent.style.maxHeight = '80vh';
4750

51+
const progressMessage = dom.$('span');
52+
progressMessage.textContent = localize('loading', 'Rendering tool output...');
53+
const progressPart = this.instantiationService.createInstance(ChatCustomProgressPart, progressMessage, ThemeIcon.modify(Codicon.loading, 'spin'));
54+
parent.appendChild(progressPart.domNode);
55+
4856
this.chatOutputItemRendererService.renderOutputPart(details.output.mimeType, details.output.value.buffer, parent, CancellationToken.None).then((renderedItem) => {
4957
this._register(renderedItem);
5058

59+
progressPart.domNode.remove();
60+
5161
this._onDidChangeHeight.fire();
5262
this._register(renderedItem.onDidChangeHeight(() => {
5363
this._onDidChangeHeight.fire();

src/vs/workbench/contrib/chat/common/chatProgressTypes/chatToolInvocation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ export class ChatToolInvocation implements IChatToolInvocation {
108108
isConfirmed: this._isConfirmed,
109109
isComplete: this._isComplete,
110110
resultDetails: isToolResultOutputDetails(this._resultDetails)
111-
? { type: 'data', mimeType: this._resultDetails.output.mimeType, base64Data: encodeBase64(this._resultDetails.output.value) }
111+
? { output: { type: 'data', mimeType: this._resultDetails.output.mimeType, base64Data: encodeBase64(this._resultDetails.output.value) } }
112112
: this._resultDetails,
113113
toolSpecificData: this.toolSpecificData,
114114
toolCallId: this.toolCallId,

src/vs/workbench/contrib/chat/common/chatService.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -282,9 +282,11 @@ export interface IChatToolInvocation {
282282
}
283283

284284
export interface IToolResultOutputDetailsSerialized {
285-
type: 'data';
286-
mimeType: string;
287-
base64Data: string;
285+
output: {
286+
type: 'data';
287+
mimeType: string;
288+
base64Data: string;
289+
};
288290
}
289291

290292
/**

src/vs/workbench/contrib/chat/common/languageModelToolsService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ export function isToolResultInputOutputDetails(obj: any): obj is IToolResultInpu
157157
}
158158

159159
export function isToolResultOutputDetails(obj: any): obj is IToolResultOutputDetails {
160-
return typeof obj === 'object' && typeof obj?.mimeType === 'string' && obj?.type === 'data';
160+
return typeof obj === 'object' && typeof obj?.output === 'object' && typeof obj?.output?.mimeType === 'string' && obj?.output?.type === 'data';
161161
}
162162

163163
export interface IToolResult {

0 commit comments

Comments
 (0)