111 lines
3.1 KiB
C#
111 lines
3.1 KiB
C#
namespace MarketAlly.GitCommitEditor.Services;
|
|
|
|
/// <summary>
|
|
/// Tracks AI operation costs for the session
|
|
/// </summary>
|
|
public interface ICostTrackingService
|
|
{
|
|
/// <summary>
|
|
/// Total cost for the current session
|
|
/// </summary>
|
|
decimal SessionCost { get; }
|
|
|
|
/// <summary>
|
|
/// Total cost across all sessions (lifetime)
|
|
/// </summary>
|
|
decimal LifetimeCost { get; }
|
|
|
|
/// <summary>
|
|
/// Total input tokens used this session
|
|
/// </summary>
|
|
int TotalInputTokens { get; }
|
|
|
|
/// <summary>
|
|
/// Total output tokens used this session
|
|
/// </summary>
|
|
int TotalOutputTokens { get; }
|
|
|
|
/// <summary>
|
|
/// Number of AI operations performed this session
|
|
/// </summary>
|
|
int OperationCount { get; }
|
|
|
|
/// <summary>
|
|
/// Number of AI operations performed across all sessions (lifetime)
|
|
/// </summary>
|
|
int LifetimeOperationCount { get; }
|
|
|
|
/// <summary>
|
|
/// Records an AI operation's cost
|
|
/// </summary>
|
|
/// <param name="operationType">Type of operation (e.g., "CommitSuggestion", "GitDiagnosis")</param>
|
|
/// <param name="inputTokens">Input tokens used</param>
|
|
/// <param name="outputTokens">Output tokens used</param>
|
|
/// <param name="cost">Calculated cost</param>
|
|
void RecordOperation(string operationType, int inputTokens, int outputTokens, decimal cost);
|
|
|
|
/// <summary>
|
|
/// Gets the cost breakdown by operation type
|
|
/// </summary>
|
|
IReadOnlyDictionary<string, OperationCostSummary> GetCostBreakdown();
|
|
|
|
/// <summary>
|
|
/// Resets session tracking (keeps lifetime totals)
|
|
/// </summary>
|
|
void ResetSession();
|
|
|
|
/// <summary>
|
|
/// Resets all tracking including lifetime totals
|
|
/// </summary>
|
|
void ResetAll();
|
|
|
|
/// <summary>
|
|
/// Saves the current state to persistent storage
|
|
/// </summary>
|
|
void SaveState();
|
|
|
|
/// <summary>
|
|
/// Loads state from persistent storage
|
|
/// </summary>
|
|
void LoadState();
|
|
|
|
/// <summary>
|
|
/// Event raised when costs are updated
|
|
/// </summary>
|
|
event EventHandler<CostUpdatedEventArgs>? CostUpdated;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Summary of costs for a specific operation type
|
|
/// </summary>
|
|
public class OperationCostSummary
|
|
{
|
|
public string OperationType { get; set; } = string.Empty;
|
|
public int Count { get; set; }
|
|
public int TotalInputTokens { get; set; }
|
|
public int TotalOutputTokens { get; set; }
|
|
public decimal TotalCost { get; set; }
|
|
public decimal AverageCost => Count > 0 ? TotalCost / Count : 0;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Event args for cost updates
|
|
/// </summary>
|
|
public class CostUpdatedEventArgs : EventArgs
|
|
{
|
|
public string OperationType { get; }
|
|
public decimal OperationCost { get; }
|
|
public decimal SessionTotal { get; }
|
|
public int InputTokens { get; }
|
|
public int OutputTokens { get; }
|
|
|
|
public CostUpdatedEventArgs(string operationType, decimal operationCost, decimal sessionTotal, int inputTokens, int outputTokens)
|
|
{
|
|
OperationType = operationType;
|
|
OperationCost = operationCost;
|
|
SessionTotal = sessionTotal;
|
|
InputTokens = inputTokens;
|
|
OutputTokens = outputTokens;
|
|
}
|
|
}
|