Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/src/platform/endpoint/common/thinkingDataContainer.tsx
13401 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
import { BasePromptElementProps, PromptElement, Raw } from '@vscode/prompt-tsx';
6
import { ThinkingData } from '../../thinking/common/thinking';
7
import { CustomDataPartMimeTypes } from './endpointTypes';
8
9
interface IThinkingDataOpaque {
10
type: typeof CustomDataPartMimeTypes.ThinkingData;
11
thinking: ThinkingData;
12
}
13
14
export interface IThinkingDataContainerProps extends BasePromptElementProps {
15
thinking: ThinkingData;
16
}
17
18
/**
19
* Helper element to embed thinking data into assistant messages
20
* as an opaque content part.
21
*/
22
export class ThinkingDataContainer extends PromptElement<IThinkingDataContainerProps> {
23
render() {
24
const { thinking } = this.props;
25
const container: IThinkingDataOpaque = { type: CustomDataPartMimeTypes.ThinkingData, thinking };
26
return <opaque value={container} tokenUsage={thinking.tokens} />;
27
}
28
}
29
30
/**
31
* Attempts to parse a Raw opaque content part into ThinkingData, if the type matches.
32
*/
33
export function rawPartAsThinkingData(part: Raw.ChatCompletionContentPartOpaque): ThinkingData | undefined {
34
const value = part.value as unknown;
35
if (!value || typeof value !== 'object') {
36
return;
37
}
38
39
const data = value as IThinkingDataOpaque;
40
if (data.type === CustomDataPartMimeTypes.ThinkingData && data.thinking && typeof data.thinking === 'object') {
41
return data.thinking;
42
}
43
return;
44
}
45
46