"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CompactionDataContainer = void 0;
exports.rawPartAsCompactionData = rawPartAsCompactionData;
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/
const prompt_tsx_1 = require("@vscode/prompt-tsx");
const endpointTypes_1 = require("./endpointTypes");
/**
 * Helper element to embed compaction data into assistant messages
 * as an opaque content part, for round-tripping in Responses API requests.
 */
class CompactionDataContainer extends prompt_tsx_1.PromptElement {
    render() {
        const { compaction } = this.props;
        const container = { type: endpointTypes_1.CustomDataPartMimeTypes.ContextManagement, compaction };
        return vscpp("opaque", { value: container });
    }
}
exports.CompactionDataContainer = CompactionDataContainer;
/**
 * Attempts to parse a Raw opaque content part into compaction data, if the type matches.
 */
function rawPartAsCompactionData(part) {
    const value = part.value;
    if (!value || typeof value !== 'object') {
        return;
    }
    const data = value;
    if (data.type === endpointTypes_1.CustomDataPartMimeTypes.ContextManagement && data.compaction && typeof data.compaction === 'object') {
        return data.compaction;
    }
    return;
}
//# sourceMappingURL=compactionDataContainer.js.map