AutoBE
    Preparing search index...

    Class AutoBeTokenUsage

    Comprehensive token usage tracker for the AutoBe vibe coding system.

    This class provides centralized tracking and management of token consumption across all AI agents in the automated development pipeline. It captures detailed token usage statistics for each processing phase - from initial requirements analysis through final implementation - enabling cost monitoring, performance optimization, and resource utilization analysis.

    The token usage data includes both input tokens (with cache efficiency) and output tokens (with generation type breakdowns), providing insights into AI processing efficiency and helping optimize the balance between computational costs and output quality.

    SunRabbit123

    Implements

    Index

    Constructors

    • Default Constructor.

      Creates a new token usage tracker with all agent phases initialized to empty components. Each component starts with zero values for all token counters, providing a clean slate for tracking token consumption from the beginning of a vibe coding session.

      Returns AutoBeTokenUsage

    • Binding Constructor.

      Creates a new instance that shares component references with the provided AutoBeTokenUsage instance. This establishes a bound relationship where both instances point to the same component objects. Any modifications to token counts through either instance will be reflected in both, enabling shared tracking across different contexts.

      Parameters

      Returns AutoBeTokenUsage

    • Initializer Constructor.

      Reconstructs a token usage tracker from serialized JSON data. Creates new AutoBeTokenUsageComponent instances for each agent phase, initializing them with the corresponding values from the JSON structure. This enables restoration of token usage state from persisted data or transmission between different parts of the system.

      Parameters

      Returns AutoBeTokenUsage

    Properties

    Token usage for the requirements analysis agent.

    Captures tokens used during the analysis phase where user requirements are processed, understood, and transformed into structured specifications for subsequent development phases.

    Token usage for the facade agent orchestrating the entire pipeline.

    Tracks tokens consumed by the initial agent that coordinates and manages the overall vibe coding process, including request parsing and response orchestration.

    Token usage for the API interface specification agent.

    Tracks tokens used in creating OpenAPI/Swagger specifications, defining endpoints, request/response structures, and API documentation.

    Token usage for the Prisma database schema generation agent.

    Records tokens consumed while designing and generating database schemas, including entity relationships, field definitions, and database-specific optimizations.

    Token usage for the implementation realization agent.

    Captures tokens used in the final implementation phase where actual business logic, controllers, services, and integration code are generated.

    Token usage for the test code generation agent.

    Monitors tokens consumed during automated test creation, including scenario planning, test case generation, and end-to-end test implementation.

    Accessors

    • Aggregated token usage statistics across all agents.

      Provides a unified view of token consumption by combining data from all processing phases in the vibe coding pipeline. This computed property dynamically calculates the sum of all agent components (facade, analyze, prisma, interface, test, realize) whenever accessed, ensuring the aggregate always reflects the current state of token usage.

      The aggregation performs element-wise addition across all token metrics, including total counts, input breakdowns with cache statistics, and output categorizations by generation type. This comprehensive view enables overall cost assessment and resource utilization analysis for the entire automated development session.

      Returns IAutoBeTokenUsageJson.IComponent

    Methods

    • Increment current token usage with data from another instance.

      Adds token usage statistics from another AutoBeTokenUsage instance to this one, updating all agent phases simultaneously. This method is useful for combining token usage from parallel processing, multiple runs, or when aggregating statistics from distributed agent executions.

      Parameters

      Returns AutoBeTokenUsage

      This instance for method chaining

    • Record token usage for specific processing stages.

      Updates token consumption statistics for one or more agent phases based on the provided usage data. This method allows selective recording of token usage for specific stages, enabling fine-grained tracking during multi-phase processing or when certain agents are invoked multiple times.

      Parameters

      • usage: IAutoBeTokenUsageJson.IComponent

        Token usage component data to record

      • additionalStages: (keyof IAutoBeApplication)[] = []

        Array of stage names to update with the usage data

      Returns void

        tokenUsage.record(
      { total: 150, input: { total: 100, cached: 20 }, output: { total: 50, ... } },
      ['analyze', 'prisma']
      );
    • Serialize token usage data to JSON format.

      Converts the internal token usage representation to the standardized IAutoBeTokenUsageJson format, suitable for persistence, transmission, or external analysis. The serialized data maintains the complete structure including all agent phases and detailed token breakdowns.

      Returns IAutoBeTokenUsageJson

      JSON representation of token usage statistics

    • Create a new instance combining token usage from two sources.

      Performs element-wise addition of token usage statistics from two AutoBeTokenUsage instances, creating a new instance with the combined totals. This static method is useful for aggregating token usage across multiple vibe coding sessions or when merging statistics from different execution contexts.

      Parameters

      Returns AutoBeTokenUsage

      New instance with combined token usage statistics