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};

/// SessionResource : A Managed Agents session.
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, bon::Builder)]
pub struct SessionResource {
    /// Custom string key-value pairs attached to the session.
    #[serde(rename = "metadata")]
    pub metadata: std::collections::HashMap<String, String>,
    /// The ID of the session.
    #[serde(rename = "id")]
    pub id: String,
    /// The object type. Always `agent.session`.
    #[serde(rename = "object")]
    pub object: Object,
    /// The Unix timestamp, in seconds, when the session was created.
    #[serde(rename = "created_at")]
    pub created_at: i64,
    /// The Unix timestamp, in seconds, when the session was last active.
    #[serde(rename = "last_active_at")]
    pub last_active_at: i64,
    #[serde(rename = "status")]
    pub status: models::SessionStatusResource,
    /// Actions that must be completed before the session can continue.
    #[serde(rename = "required_actions")]
    pub required_actions: Vec<models::SessionRequiredActionResource>,
    /// The error that caused the session to fail, if any.
    #[serde(rename = "error", deserialize_with = "Option::deserialize")]
    pub error: Option<String>,
    #[serde(rename = "agent")]
    pub agent: models::SessionAgentResource,
    #[serde(rename = "environment")]
    pub environment: Box<models::EnvironmentResource>,
    /// The IDs of vaults made available to the session.
    #[serde(rename = "vault_ids")]
    pub vault_ids: Vec<String>,
    #[serde(rename = "usage", deserialize_with = "Option::deserialize")]
    pub usage: Option<models::TokenUsageResource>,
}

impl SessionResource {
    /// A Managed Agents session.
    pub fn new(
        metadata: std::collections::HashMap<String, String>,
        id: String,
        object: Object,
        created_at: i64,
        last_active_at: i64,
        status: models::SessionStatusResource,
        required_actions: Vec<models::SessionRequiredActionResource>,
        error: Option<String>,
        agent: models::SessionAgentResource,
        environment: models::EnvironmentResource,
        vault_ids: Vec<String>,
        usage: Option<models::TokenUsageResource>,
    ) -> SessionResource {
        SessionResource {
            metadata,
            id,
            object,
            created_at,
            last_active_at,
            status,
            required_actions,
            error,
            agent,
            environment: Box::new(environment),
            vault_ids,
            usage,
        }
    }
}
/// The object type. Always `agent.session`.
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
pub enum Object {
    #[serde(rename = "agent.session")]
    AgentSession,
}

impl Default for Object {
    fn default() -> Object {
        Self::AgentSession
    }
}

impl std::fmt::Display for SessionResource {
    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),
        }
    }
}