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