use crate::msp::method::turn::CommandStatus;
use crate::msp::view::item_content::BackgroundInitiator;
use serde::Deserialize;
use serde::Deserializer;
use serde::Serialize;
use serde::Serializer;
mod catch_all;
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct TaskBackgroundParams {
pub session_id: String,
pub command_id: String,
pub task_id: String,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct TaskStopParams {
pub session_id: String,
pub command_id: String,
pub task_id: String,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct TaskStopAllParams {
pub session_id: String,
pub command_id: String,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
#[non_exhaustive]
pub struct TaskCommandResult {
pub command_id: String,
pub status: CommandStatus,
pub task_id: String,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
#[non_exhaustive]
pub struct TaskStopAllResult {
pub command_id: String,
pub status: CommandStatus,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct TaskListParams {
pub session_id: String,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
#[non_exhaustive]
pub struct TaskListResult {
pub tasks: Vec<TaskListEntry>,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
#[non_exhaustive]
pub struct TaskListEntry {
pub task_id: String,
pub kind: String,
pub status: TaskListStatus,
#[serde(skip_serializing_if = "Option::is_none")]
pub tool: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub started_at: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub background_initiator: Option<BackgroundInitiator>,
#[serde(skip_serializing_if = "Option::is_none")]
pub execution_mode: Option<TaskExecutionMode>,
#[serde(skip_serializing_if = "Option::is_none")]
pub command: Option<String>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum TaskListStatus {
InProgress,
Unknown(String),
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum TaskExecutionMode {
Foreground,
Background,
Unknown(String),
}
impl TaskExecutionMode {
#[must_use]
pub fn as_str(&self) -> &str {
match self {
Self::Foreground => "foreground",
Self::Background => "background",
Self::Unknown(value) => value,
}
}
}
impl Serialize for TaskExecutionMode {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
serializer.serialize_str(self.as_str())
}
}
impl<'de> Deserialize<'de> for TaskExecutionMode {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
let value = String::deserialize(deserializer)?;
Ok(match value.as_str() {
"foreground" => Self::Foreground,
"background" => Self::Background,
_ => Self::Unknown(value),
})
}
}