// Copyright (c) Microsoft. All rights reserved.
using System.Diagnostics.CodeAnalysis;
using System.Text.Json;
using System.Text.Json.Serialization;
using Microsoft.Extensions.AI;
namespace Microsoft.Agents.AI.DurableTask.State;
///
/// Represents the token usage details for a durable agent state response.
///
internal sealed class DurableAgentStateUsage
{
///
/// Gets the number of input tokens used.
///
[JsonPropertyName("inputTokenCount")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public long? InputTokenCount { get; init; }
///
/// Gets the number of output tokens used.
///
[JsonPropertyName("outputTokenCount")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public long? OutputTokenCount { get; init; }
///
/// Gets the total number of tokens used.
///
[JsonPropertyName("totalTokenCount")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public long? TotalTokenCount { get; init; }
///
/// Gets any additional data found during deserialization that does not map to known properties.
///
[JsonExtensionData]
public IDictionary? ExtensionData { get; set; }
///
/// Creates a from a .
///
/// The to convert.
/// A representing the original usage details.
[return: NotNullIfNotNull(nameof(usage))]
public static DurableAgentStateUsage? FromUsage(UsageDetails? usage) =>
usage is not null
? new()
{
InputTokenCount = usage.InputTokenCount,
OutputTokenCount = usage.OutputTokenCount,
TotalTokenCount = usage.TotalTokenCount
}
: null;
///
/// Converts this back to a .
///
/// A representing this usage.
public UsageDetails ToUsageDetails()
{
return new()
{
InputTokenCount = this.InputTokenCount,
OutputTokenCount = this.OutputTokenCount,
TotalTokenCount = this.TotalTokenCount
};
}
}