Path: blob/main/extensions/copilot/src/platform/endpoint/common/phaseDataContainer.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 { CustomDataPartMimeTypes } from './endpointTypes';67interface IPhaseDataOpaque {8type: typeof CustomDataPartMimeTypes.PhaseData;9phase: string;10}1112export interface IPhaseDataContainerProps extends BasePromptElementProps {13phase: string;14}1516/**17* Helper element to embed phase data into assistant messages18* as an opaque content part.19*/20export class PhaseDataContainer extends PromptElement<IPhaseDataContainerProps> {21render() {22const { phase } = this.props;23const container: IPhaseDataOpaque = { type: CustomDataPartMimeTypes.PhaseData, phase };24return <opaque value={container} />;25}26}2728/**29* Attempts to parse a Raw opaque content part into a phase string, if the type matches.30*/31export function rawPartAsPhaseData(part: Raw.ChatCompletionContentPartOpaque): string | undefined {32const value = part.value as unknown;33if (!value || typeof value !== 'object') {34return;35}3637const data = value as IPhaseDataOpaque;38if (data.type === CustomDataPartMimeTypes.PhaseData && typeof data.phase === 'string') {39return data.phase;40}41return;42}434445