58 lines
2.3 KiB
C#
58 lines
2.3 KiB
C#
using MarketAlly.GitCommitEditor.Resources;
|
|
|
|
namespace MarketAlly.GitCommitEditor.Models;
|
|
|
|
/// <summary>
|
|
/// Result of a push operation.
|
|
/// </summary>
|
|
public sealed record GitPushResult(bool Success, string Message)
|
|
{
|
|
public static GitPushResult Ok(string? message = null) => new(true, message ?? Str.Service_PushSuccess);
|
|
public static GitPushResult Fail(string message) => new(false, message);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tracking information for a branch.
|
|
/// </summary>
|
|
public sealed record TrackingInfo(
|
|
string? UpstreamBranch,
|
|
int? AheadBy,
|
|
int? BehindBy)
|
|
{
|
|
public static TrackingInfo None => new(null, null, null);
|
|
public bool HasUpstream => UpstreamBranch != null;
|
|
public bool IsInSync => AheadBy == 0 && BehindBy == 0;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Result of an AI suggestion operation.
|
|
/// </summary>
|
|
public sealed record SuggestionResult(
|
|
CommitAnalysis? Analysis,
|
|
string? Suggestion,
|
|
string? ErrorMessage = null,
|
|
string? RawResponse = null,
|
|
bool ReturnedOriginal = false,
|
|
int InputTokens = 0,
|
|
int OutputTokens = 0,
|
|
decimal EstimatedCost = 0)
|
|
{
|
|
public bool Success => ErrorMessage == null && Suggestion != null;
|
|
public int TotalTokens => InputTokens + OutputTokens;
|
|
|
|
public static SuggestionResult Ok(CommitAnalysis analysis, string suggestion, int inputTokens = 0, int outputTokens = 0, decimal cost = 0)
|
|
=> new(analysis, suggestion, InputTokens: inputTokens, OutputTokens: outputTokens, EstimatedCost: cost);
|
|
|
|
public static SuggestionResult Succeeded(string suggestion, int inputTokens = 0, int outputTokens = 0, decimal cost = 0)
|
|
=> new(null, suggestion, InputTokens: inputTokens, OutputTokens: outputTokens, EstimatedCost: cost);
|
|
|
|
public static SuggestionResult Fail(CommitAnalysis analysis, string error)
|
|
=> new(analysis, null, error);
|
|
|
|
public static SuggestionResult Failed(string error, string? rawResponse = null)
|
|
=> new(null, null, error, rawResponse);
|
|
|
|
public static SuggestionResult FailedWithOriginal(string originalMessage, string? rawResponse = null, int inputTokens = 0, int outputTokens = 0, decimal cost = 0)
|
|
=> new(null, originalMessage, Str.Service_AiFallback, rawResponse, ReturnedOriginal: true, InputTokens: inputTokens, OutputTokens: outputTokens, EstimatedCost: cost);
|
|
}
|