use crate::models;
use serde::{Deserialize, Serialize};
#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize, bon::Builder)]
pub struct CommandExecutionItemResource {
#[serde(rename = "type")]
pub r#type: Type,
#[serde(rename = "id")]
pub id: String,
#[serde(rename = "turn_id")]
pub turn_id: String,
#[serde(rename = "command")]
pub command: String,
#[serde(rename = "cwd", deserialize_with = "Option::deserialize")]
pub cwd: Option<String>,
#[serde(rename = "status")]
pub status: models::FunctionCallStatusResource,
#[serde(rename = "output", deserialize_with = "Option::deserialize")]
pub output: Option<String>,
#[serde(rename = "exit_code", deserialize_with = "Option::deserialize")]
pub exit_code: Option<i64>,
#[serde(rename = "duration_ms", deserialize_with = "Option::deserialize")]
pub duration_ms: Option<i64>,
}
impl CommandExecutionItemResource {
pub fn new(
r#type: Type,
id: String,
turn_id: String,
command: String,
cwd: Option<String>,
status: models::FunctionCallStatusResource,
output: Option<String>,
exit_code: Option<i64>,
duration_ms: Option<i64>,
) -> CommandExecutionItemResource {
CommandExecutionItemResource {
r#type,
id,
turn_id,
command,
cwd,
status,
output,
exit_code,
duration_ms,
}
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
pub enum Type {
#[serde(rename = "command_execution")]
CommandExecution,
}
impl Default for Type {
fn default() -> Type {
Self::CommandExecution
}
}
impl std::fmt::Display for CommandExecutionItemResource {
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),
}
}
}