Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/src/extension/agentDebug/vscode-node/toolResultContentRenderer.ts
13399 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import { LanguageModelDataPart, LanguageModelPromptTsxPart, LanguageModelTextPart } from '../../../vscodeTypes';
7
import { renderDataPartToString } from '../../prompt/vscode-node/requestLoggerToolResult';
8
import { IToolResultContentRenderer } from '../common/toolResultRenderer';
9
10
export class ToolResultContentRenderer implements IToolResultContentRenderer {
11
readonly _serviceBrand: undefined;
12
13
renderToolResultContent(content: Iterable<unknown>): string[] {
14
const parts: string[] = [];
15
for (const part of content) {
16
if (part instanceof LanguageModelTextPart) {
17
parts.push(part.value);
18
} else if (part instanceof LanguageModelPromptTsxPart) {
19
// Use lightweight JSON serialization instead of expensive renderPrompt().
20
// This runs on every tool call, so avoid async TSX rendering overhead.
21
try {
22
parts.push(JSON.stringify(part.value, null, 2));
23
} catch {
24
parts.push('[PromptTsxPart]');
25
}
26
} else if (part instanceof LanguageModelDataPart) {
27
parts.push(renderDataPartToString(part));
28
}
29
}
30
return parts;
31
}
32
}
33
34