"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.AutoBeTokenUsageComponent = void 0;
/**
 * Token usage component for individual AI agents in the vibe coding pipeline.
 *
 * Represents detailed token consumption statistics for a specific processing
 * phase (facade, analyze, prisma, interface, test, or realize). This class
 * tracks both input and output token usage with granular breakdowns, enabling
 * precise cost analysis and performance optimization for each agent.
 *
 * The component structure includes:
 *
 * - Total token count for quick cost calculations
 * - Input token breakdown with cache efficiency metrics
 * - Output token categorization by generation type
 *
 * This granular tracking helps identify optimization opportunities and
 * understand the computational characteristics of each agent phase.
 *
 * @author SunRabbit123
 */
class AutoBeTokenUsageComponent {
    /**
     * Total token count combining all input and output tokens.
     *
     * Represents the complete token consumption for this component, providing a
     * single metric for overall resource utilization. This value is critical for
     * cost calculations and comparing efficiency across different agents or
     * processing phases.
     */
    get total() {
        return this.input.total + this.output.total;
    }
    constructor(props) {
        if (props === undefined) {
            this.input = { total: 0, cached: 0 };
            this.output = {
                total: 0,
                reasoning: 0,
                accepted_prediction: 0,
                rejected_prediction: 0,
            };
        }
        else {
            this.input = props.input;
            this.output = props.output;
        }
    }
    assign(props) {
        this.input.total = props.input.total;
        this.input.cached = props.input.cached;
        this.output.total = props.output.total;
        this.output.reasoning = props.output.reasoning;
        this.output.accepted_prediction = props.output.accepted_prediction;
        this.output.rejected_prediction = props.output.rejected_prediction;
    }
    /**
     * Export token usage data as JSON.
     *
     * Converts the component's token usage statistics to the standardized
     * IAutoBeTokenUsageJson.IComponent format. This serialization maintains the
     * complete structure including total counts and detailed breakdowns for both
     * input and output tokens.
     *
     * @returns JSON representation of the token usage component
     */
    toJSON() {
        return {
            total: this.total,
            input: {
                total: this.input.total,
                cached: this.input.cached,
            },
            output: {
                total: this.output.total,
                reasoning: this.output.reasoning,
                accepted_prediction: this.output.accepted_prediction,
                rejected_prediction: this.output.rejected_prediction,
            },
        };
    }
    /* -----------------------------------------------------------
      OPERATORS
    ----------------------------------------------------------- */
    /**
     * Add token usage data to current statistics.
     *
     * Increments all token counters in this component by the corresponding values
     * from the provided component data. This method performs in-place updates,
     * modifying the current instance rather than creating a new one.
     *
     * Updates include:
     *
     * - Total token count
     * - Input tokens (both total and cached)
     * - Output tokens (reasoning, accepted/rejected predictions)
     *
     * @param props - Token usage component data to add to current values
     */
    increment(props) {
        this.input.total += props.input.total;
        this.input.cached += props.input.cached;
        this.output.total += props.output.total;
        this.output.reasoning += props.output.reasoning;
        this.output.accepted_prediction += props.output.accepted_prediction;
        this.output.rejected_prediction += props.output.rejected_prediction;
    }
    /** @internal */
    decrement(props) {
        this.input.total -= props.input.total;
        this.input.cached -= props.input.cached;
        this.output.total -= props.output.total;
        this.output.reasoning -= props.output.reasoning;
        this.output.accepted_prediction -= props.output.accepted_prediction;
        this.output.rejected_prediction -= props.output.rejected_prediction;
    }
    /**
     * Create new component combining two token usage statistics.
     *
     * Performs element-wise addition of all token counters from two components,
     * creating a new AutoBeTokenUsageComponent instance with the combined totals.
     * This static method is useful for aggregating token usage across multiple
     * agent invocations or combining statistics from parallel processing.
     *
     * @param a - First token usage component
     * @param b - Second token usage component
     * @returns New component with combined token statistics
     */
    static plus(a, b) {
        return new AutoBeTokenUsageComponent({
            input: {
                total: a.input.total + b.input.total,
                cached: a.input.cached + b.input.cached,
            },
            output: {
                total: a.output.total + b.output.total,
                reasoning: a.output.reasoning + b.output.reasoning,
                accepted_prediction: a.output.accepted_prediction + b.output.accepted_prediction,
                rejected_prediction: a.output.rejected_prediction + b.output.rejected_prediction,
            },
        });
    }
    static minus(a, b) {
        return new AutoBeTokenUsageComponent({
            input: {
                total: a.input.total - b.input.total,
                cached: a.input.cached - b.input.cached,
            },
            output: {
                total: a.output.total - b.output.total,
                reasoning: a.output.reasoning - b.output.reasoning,
                accepted_prediction: a.output.accepted_prediction - b.output.accepted_prediction,
                rejected_prediction: a.output.rejected_prediction - b.output.rejected_prediction,
            },
        });
    }
}
exports.AutoBeTokenUsageComponent = AutoBeTokenUsageComponent;
//# sourceMappingURL=AutoBeTokenUsageComponent.js.map