Path: blob/main/extensions/copilot/src/platform/endpoint/common/thinkingDataContainer.tsx
13401 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/4import { BasePromptElementProps, PromptElement, Raw } from '@vscode/prompt-tsx';5import { ThinkingData } from '../../thinking/common/thinking';6import { CustomDataPartMimeTypes } from './endpointTypes';78interface IThinkingDataOpaque {9type: typeof CustomDataPartMimeTypes.ThinkingData;10thinking: ThinkingData;11}1213export interface IThinkingDataContainerProps extends BasePromptElementProps {14thinking: ThinkingData;15}1617/**18* Helper element to embed thinking data into assistant messages19* as an opaque content part.20*/21export class ThinkingDataContainer extends PromptElement<IThinkingDataContainerProps> {22render() {23const { thinking } = this.props;24const container: IThinkingDataOpaque = { type: CustomDataPartMimeTypes.ThinkingData, thinking };25return <opaque value={container} tokenUsage={thinking.tokens} />;26}27}2829/**30* Attempts to parse a Raw opaque content part into ThinkingData, if the type matches.31*/32export function rawPartAsThinkingData(part: Raw.ChatCompletionContentPartOpaque): ThinkingData | undefined {33const value = part.value as unknown;34if (!value || typeof value !== 'object') {35return;36}3738const data = value as IThinkingDataOpaque;39if (data.type === CustomDataPartMimeTypes.ThinkingData && data.thinking && typeof data.thinking === 'object') {40return data.thinking;41}42return;43}444546