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

/// SubagentResource : A subagent created within a session.
#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize, bon::Builder)]
pub struct SubagentResource {
    /// The ID of the subagent.
    #[serde(rename = "id")]
    pub id: String,
    #[serde(rename = "object")]
    pub object: models::SubagentObjectResource,
    /// The ID of the session that owns the subagent.
    #[serde(rename = "session_id")]
    pub session_id: String,
    /// The runner-assigned nickname, or null when unavailable.
    #[serde(rename = "name", deserialize_with = "Option::deserialize")]
    pub name: Option<String>,
    /// Initial task content, or null when unavailable. Text may contain placeholders for images or audio when only a preview is available.
    #[serde(rename = "instructions", deserialize_with = "Option::deserialize")]
    pub instructions: Option<Vec<models::AgentContentResource>>,
    /// The ID of the agent that created this subagent.
    #[serde(rename = "parent_agent_id")]
    pub parent_agent_id: String,
    #[serde(rename = "status")]
    pub status: models::SubagentStatusResource,
    /// The Unix timestamp, in seconds, when the subagent was first opened. Resuming does not change it.
    #[serde(rename = "opened_at")]
    pub opened_at: i64,
    /// The Unix timestamp, in seconds, when the subagent was closed. Null while active, including after resume.
    #[serde(rename = "closed_at", deserialize_with = "Option::deserialize")]
    pub closed_at: Option<i64>,
}

impl SubagentResource {
    /// A subagent created within a session.
    pub fn new(
        id: String,
        object: models::SubagentObjectResource,
        session_id: String,
        name: Option<String>,
        instructions: Option<Vec<models::AgentContentResource>>,
        parent_agent_id: String,
        status: models::SubagentStatusResource,
        opened_at: i64,
        closed_at: Option<i64>,
    ) -> SubagentResource {
        SubagentResource {
            id,
            object,
            session_id,
            name,
            instructions,
            parent_agent_id,
            status,
            opened_at,
            closed_at,
        }
    }
}

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