UNPKG

@autobe/agent

Version:

AI backend server code generator

119 lines (118 loc) 5 kB
import { IAutoBeTokenUsageJson } from "@autobe/interface"; /** * 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 */ export declare class AutoBeTokenUsageComponent implements IAutoBeTokenUsageJson.IComponent { /** * Detailed breakdown of input token consumption. * * Tracks how many tokens were processed as input to the AI agent, including: * * - Total input tokens processed * - Cached tokens that were reused from previous operations * * The cache efficiency (cached/total ratio) indicates how well the system is * reusing context across multiple invocations. */ readonly input: IAutoBeTokenUsageJson.IInput; /** * Detailed breakdown of output token generation. * * Categorizes generated tokens by their purpose and acceptance status: * * - Total output tokens generated * - Reasoning tokens (internal processing) * - Accepted prediction tokens (efficient generation) * - Rejected prediction tokens (quality control overhead) * * These metrics help understand the AI's generation efficiency and the * effectiveness of its predictive mechanisms. */ readonly output: IAutoBeTokenUsageJson.IOutput; /** * 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(): number; /** * Default Constructor. * * Creates a new token usage component with all counters initialized to zero. * Constructs fresh input and output objects with default values, providing a * clean starting point for tracking token consumption in an agent phase. */ constructor(); /** * Initializer Constructor. * * Creates a new component populated with existing token usage data. Directly * assigns the provided values to instance properties, preserving the exact * token counts and structure from the source data for accurate tracking * continuation. * * @param props - Token usage data to initialize the component */ constructor(props: Omit<IAutoBeTokenUsageJson.IComponent, "total">); assign(props: IAutoBeTokenUsageJson.IComponent): void; /** * 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(): IAutoBeTokenUsageJson.IComponent; /** * 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: IAutoBeTokenUsageJson.IComponent): void; /** * 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: AutoBeTokenUsageComponent, b: AutoBeTokenUsageComponent): AutoBeTokenUsageComponent; static minus(a: AutoBeTokenUsageComponent, b: AutoBeTokenUsageComponent): AutoBeTokenUsageComponent; }