pub struct AgentRoleResponse {
pub name: String,
pub period: String,
pub period_start: DateTime<Utc>,
pub resets_at: DateTime<Utc>,
pub code_cap_usd: Option<Decimal>,
pub operator_cap_usd: Option<Decimal>,
pub cap_usd: Option<Decimal>,
pub spent_usd: Decimal,
pub reserved_usd: Decimal,
pub remaining_usd: Option<Decimal>,
pub updated_at: DateTime<Utc>,
}Expand description
Cost consumed by an agent role over its current period, and its cap.
§Examples
use chrono::Utc;
use ironflow_api::entities::AgentRoleResponse;
use ironflow_store::entities::AgentRoleRecord;
use rust_decimal::Decimal;
use uuid::Uuid;
let now = Utc::now();
let record = AgentRoleRecord {
id: Uuid::now_v7(),
name: "reviewer".to_string(),
code_cap_usd: Some(Decimal::TEN),
operator_cap_usd: None,
period: "month".to_string(),
period_start: now,
spent_usd: Decimal::TWO,
reserved_usd: Decimal::ONE,
created_at: now,
updated_at: now,
};
let response = AgentRoleResponse::from_record(record, now)?;
assert_eq!(response.remaining_usd, Some(Decimal::new(7, 0)));Fields§
§name: StringName of the role, as declared by AgentRole::name.
period: StringPeriod of the counter: day or month (calendar, UTC).
period_start: DateTime<Utc>Start of the current period.
resets_at: DateTime<Utc>When the counter resets.
code_cap_usd: Option<Decimal>Cap declared in code, as last seen by a step of the role.
operator_cap_usd: Option<Decimal>Cap set by an operator; it can only lower the code cap.
cap_usd: Option<Decimal>Cap enforced: the lower of the code and operator caps.
spent_usd: DecimalCost settled in the current period.
reserved_usd: DecimalCost held by the steps of the role running now.
remaining_usd: Option<Decimal>Room left under the cap, never negative. null without a cap.
updated_at: DateTime<Utc>Last change of the counter or of a cap.
Implementations§
Source§impl AgentRoleResponse
impl AgentRoleResponse
Sourcepub fn from_record(
record: AgentRoleRecord,
now: DateTime<Utc>,
) -> Result<Self, ApiError>
pub fn from_record( record: AgentRoleRecord, now: DateTime<Utc>, ) -> Result<Self, ApiError>
Build the response at now. A counter whose period is over reads as
zero over the current period: the store only resets it on the next
step of the role.
§Errors
Returns ApiError::Internal if the stored period is unknown.
§Examples
See AgentRoleResponse.