openai-client-base 0.16.0

Auto-generated Rust client for the OpenAI API
/*
 * OpenAI API
 *
 * The OpenAI REST API. Please see https://platform.openai.com/docs/api-reference for more details.
 *
 * The version of the OpenAPI document: 2.3.0
 *
 * Generated by: https://openapi-generator.tech
 */

use crate::models;
use serde::{Deserialize, Serialize};

/// TurnResource : The canonical public representation of a session turn.
#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize, bon::Builder)]
pub struct TurnResource {
    /// The ID of the turn.
    #[serde(rename = "id")]
    pub id: String,
    #[serde(rename = "object")]
    pub object: models::TurnObjectResource,
    /// The ID of the session that owns the turn.
    #[serde(rename = "session_id")]
    pub session_id: String,
    /// The ID of the agent that ran the turn.
    #[serde(rename = "agent_id")]
    pub agent_id: String,
    /// The ID of the subagent that ran the turn, if applicable.
    #[serde(rename = "subagent_id", deserialize_with = "Option::deserialize")]
    pub subagent_id: Option<String>,
    #[serde(rename = "status")]
    pub status: models::TurnStatusResource,
    /// The Unix timestamp, in seconds, used to order the turn by creation time. Subagent turns use their start time, falling back to completion time or the subagent opening time when the preceding timestamps are unavailable.
    #[serde(rename = "created_at")]
    pub created_at: i64,
    /// The Unix timestamp, in seconds, when the turn started.
    #[serde(rename = "started_at", deserialize_with = "Option::deserialize")]
    pub started_at: Option<i64>,
    /// The Unix timestamp, in seconds, when the turn reached a terminal state.
    #[serde(rename = "completed_at", deserialize_with = "Option::deserialize")]
    pub completed_at: Option<i64>,
    #[serde(rename = "error", deserialize_with = "Option::deserialize")]
    pub error: Option<models::SessionTurnErrorResource>,
    #[serde(rename = "usage", deserialize_with = "Option::deserialize")]
    pub usage: Option<models::TokenUsageResource>,
}

impl TurnResource {
    /// The canonical public representation of a session turn.
    pub fn new(
        id: String,
        object: models::TurnObjectResource,
        session_id: String,
        agent_id: String,
        subagent_id: Option<String>,
        status: models::TurnStatusResource,
        created_at: i64,
        started_at: Option<i64>,
        completed_at: Option<i64>,
        error: Option<models::SessionTurnErrorResource>,
        usage: Option<models::TokenUsageResource>,
    ) -> TurnResource {
        TurnResource {
            id,
            object,
            session_id,
            agent_id,
            subagent_id,
            status,
            created_at,
            started_at,
            completed_at,
            error,
            usage,
        }
    }
}

impl std::fmt::Display for TurnResource {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match serde_json::to_string(self) {
            Ok(s) => write!(f, "{}", s),
            Err(_) => Err(std::fmt::Error),
        }
    }
}