Skip to content

Commit 57c278a

Browse files
committed
PR comment follow up
Adding a few notes and small fixes
1 parent 69aae03 commit 57c278a

File tree

4 files changed

+30
-12
lines changed

4 files changed

+30
-12
lines changed

src/vs/workbench/api/common/extHostChatOutputRenderer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,6 @@ export class ExtHostChatOutputRenderer implements ExtHostChatOutputRendererShape
4848
}
4949

5050
const webview = this.webviews.createNewWebview(webviewHandle, {}, entry.extension);
51-
return entry.renderer.renderChatOutput(valueData.buffer, webview, token);
51+
return entry.renderer.renderChatOutput(valueData.buffer, webview, {}, token);
5252
}
5353
}

src/vs/workbench/api/common/extHostTypeConverters.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3335,12 +3335,11 @@ export namespace LanguageModelToolResult2 {
33353335
if (item.kind === 'text') {
33363336
return new types.LanguageModelTextPart(item.value);
33373337
} else if (item.kind === 'data') {
3338-
// TODO: make sure we can remove this
3339-
// const mimeType = Object.values(types.ChatImageMimeType).includes(item.value.mimeType as types.ChatImageMimeType) ? item.value.mimeType as types.ChatImageMimeType : undefined;
3340-
// // if (!mimeType) {
3341-
// // throw new Error('Invalid MIME type');
3342-
// // }
3343-
return new types.LanguageModelDataPart(item.value.data.buffer, item.value.mimeType);
3338+
const mimeType = Object.values(types.ChatImageMimeType).includes(item.value.mimeType as types.ChatImageMimeType) ? item.value.mimeType as types.ChatImageMimeType : undefined;
3339+
if (!mimeType) {
3340+
throw new Error('Invalid MIME type');
3341+
}
3342+
return new types.LanguageModelDataPart(item.value.data.buffer, mimeType);
33443343
} else {
33453344
return new types.LanguageModelPromptTsxPart(item.value);
33463345
}

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

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import * as dom from '../../../../../../base/browser/dom.js';
77
import { decodeBase64 } from '../../../../../../base/common/buffer.js';
8-
import { CancellationToken } from '../../../../../../base/common/cancellation.js';
8+
import { CancellationTokenSource } from '../../../../../../base/common/cancellation.js';
99
import { Codicon } from '../../../../../../base/common/codicons.js';
1010
import { ThemeIcon } from '../../../../../../base/common/themables.js';
1111
import { localize } from '../../../../../../nls.js';
@@ -18,11 +18,14 @@ import { IChatContentPartRenderContext } from '../chatContentParts.js';
1818
import { ChatCustomProgressPart } from '../chatProgressContentPart.js';
1919
import { BaseChatToolInvocationSubPart } from './chatToolInvocationSubPart.js';
2020

21+
// TODO: see if we can reuse existing types instead of adding ChatToolOutputSubPart
2122
export 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;

src/vscode-dts/vscode.proposed.chatOutputRenderer.d.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ declare module 'vscode' {
2424

2525
export interface ExtendedLanguageModelToolResult2 extends ExtendedLanguageModelToolResult {
2626
// Temporary to allow `toolResultDetails` to return a ToolResultDataOutput
27+
// TODO: Should this live here? Or should we be able to mark each `content` items as user/lm specific?
2728
// TODO: Should we allow multiple per tool result?
2829
toolResultDetails2?: Array<Uri | Location> | ToolResultDataOutput;
2930
}
@@ -32,8 +33,10 @@ declare module 'vscode' {
3233
/**
3334
* Given an output, render it into the provided webview.
3435
*
35-
* TODO: Should we make this more generic so that we could support inputs besides tool outputs?
36-
* For example, a generic `ChatResponseDataPart` type.
36+
* TODO:Should this take an object instead of Uint8Array? That would let you get the original mime. Useful
37+
* if we ever support registering for multiple mime types or using image/*.
38+
*
39+
* TODO: Figure out what to pass as context?
3740
*
3841
* @param data The data to render.
3942
* @param webview The webview to render the data into.
@@ -42,7 +45,7 @@ declare module 'vscode' {
4245
*
4346
* @returns A promise that resolves when the webview has been initialized and is ready to be presented to the user.
4447
*/
45-
renderChatOutput(data: Uint8Array, webview: Webview, token: CancellationToken): Thenable<void>;
48+
renderChatOutput(data: Uint8Array, webview: Webview, ctx: {}, token: CancellationToken): Thenable<void>;
4649
}
4750

4851
export namespace chat {

0 commit comments

Comments
 (0)