Path: blob/main/extensions/copilot/src/platform/endpoint/common/compactionDataContainer.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 { OpenAIContextManagementResponse } from '../../networking/common/openai';6import { CustomDataPartMimeTypes } from './endpointTypes';78interface ICompactionDataOpaque {9type: typeof CustomDataPartMimeTypes.ContextManagement;10compaction: OpenAIContextManagementResponse;11}1213export interface ICompactionDataContainerProps extends BasePromptElementProps {14compaction: OpenAIContextManagementResponse;15}1617/**18* Helper element to embed compaction data into assistant messages19* as an opaque content part, for round-tripping in Responses API requests.20*/21export class CompactionDataContainer extends PromptElement<ICompactionDataContainerProps> {22render() {23const { compaction } = this.props;24const container: ICompactionDataOpaque = { type: CustomDataPartMimeTypes.ContextManagement, compaction };25return <opaque value={container} />;26}27}2829/**30* Attempts to parse a Raw opaque content part into compaction data, if the type matches.31*/32export function rawPartAsCompactionData(part: Raw.ChatCompletionContentPartOpaque): OpenAIContextManagementResponse | undefined {33const value = part.value as unknown;34if (!value || typeof value !== 'object') {35return;36}3738const data = value as ICompactionDataOpaque;39if (data.type === CustomDataPartMimeTypes.ContextManagement && data.compaction && typeof data.compaction === 'object') {40return data.compaction;41}42return;43}444546