"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.TokenReportBuilder = void 0;
class TokenReportBuilder {
    constructor(totalTokensUsed, tokenConfig, spComponentsWithTL, fpComponentsWithTL, chComponentsWithTL) {
        this.totalTokensUsed = totalTokensUsed;
        this.tokenConfig = tokenConfig;
        this.spComponentsWithTL = spComponentsWithTL;
        this.fpComponentsWithTL = fpComponentsWithTL;
        this.chComponentsWithTL = chComponentsWithTL;
    }
    build() {
        return __awaiter(this, void 0, void 0, function* () {
            // this function will interact with the SPC to get the token report
            // this token report will display the following
            // - Total Tokens Remaining:
            // - Tokens Budgetted: (just max tokens)
            // - Tokens Used: (SP + CB + ER)
            // - Total for Files: `<>`
            //   - File1: `<>`
            //   - File2: `<>`
            //   - File3: `<>`
            // - System Prompt Total Tokens: `<>`
            //   - Prefix Instruction: `<>`
            //   - Injection Files: `<>`
            //   - Sufffix Instruction: `<>`
            // - Conversation Buffer: `<>`
            // - Error Correction: `<>`
            // - (Unaccounted) Conversation History: `<>`
            // All of this information will be outputted to an object
            const fileBreakdown = this.fpComponentsWithTL.filePathsAndContentWithTokenLength.map((fpc) => {
                return {
                    fileName: fpc.fileName,
                    tokenLength: fpc.contentTokenLength,
                };
            });
            const systemPromptBreakdown = {
                prefixInstruction: this.spComponentsWithTL.prefixInstructionTokenLength,
                injectionInstruction: this.spComponentsWithTL.injectionInstructionTokenLength,
                suffixInstruction: this.spComponentsWithTL.suffixInstructionTokenLength,
            };
            const returnObject = {
                totalTokensRemaining: this.tokenConfig.maxTokens - this.totalTokensUsed,
                tokensBudgeted: this.tokenConfig.maxTokens,
                tokensUsed: this.totalTokensUsed,
                totalForFiles: this.fpComponentsWithTL.filesTotalTokenLength,
                fileBreakdown: fileBreakdown,
                systemPromptTotalTokens: this.spComponentsWithTL.completeInstructionTokenLength,
                systemPromptBreakdown: systemPromptBreakdown,
                conversationBuffer: this.tokenConfig.reservedConversationTokens,
                errorCorrection: this.tokenConfig.errorCorrectionTokens,
                unaccountedConversationHistory: this.chComponentsWithTL.conversationHistoryTokenLength,
            };
            return returnObject;
        });
    }
}
exports.TokenReportBuilder = TokenReportBuilder;
